/*
 * MIT License
 *
 * Copyright (c) 2019 Mr.css
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

package cn.seaboot.commons.reflect;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Map;

/**
 * 用于对象结构分析，分析出对象包含了多少字段，每个字段的类型，以及对象是如何嵌套的；
 * 所有的字段都会被解析成ObjectNode，ObjectNode能反映出对象的数据结构
 *
 * @author Mr.css
 * @version 2021-04-02 10:08
 */
public class ObjectProperty implements Serializable {
    private static final long serialVersionUID = 1175926363081328890L;
    /**
     * Field类型
     */
    private Class<?> type;
    /**
     * Field对象实例
     */
    private transient Field field;
    /**
     * Field对象实例
     */
    private transient ObjectField objectField;
    /**
     * 字段类型：Map、List、Object
     */
    private ObjectType objectType = ObjectType.FIELD;
    /**
     * 如果是Object类型，会包含子类型
     */
    private Map<String, ObjectProperty> properties;


    //getter/setter-------------------------------------------------


    public Class<?> getType() {
        return type;
    }

    public void setType(Class<?> type) {
        this.type = type;
    }

    public Field getField() {
        return field;
    }

    public void setField(Field field) {
        this.field = field;
    }

    public ObjectField getObjectField() {
        return objectField;
    }

    public void setObjectField(ObjectField objectField) {
        this.objectField = objectField;
    }

    public ObjectType getObjectType() {
        return objectType;
    }

    public void setObjectType(ObjectType objectType) {
        this.objectType = objectType;
    }

    public Map<String, ObjectProperty> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, ObjectProperty> properties) {
        this.properties = properties;
    }

    @Override
    public String toString() {
        return "ObjectProperty{" +
                "type=" + type +
                ", field=" + field +
                ", objectField=" + objectField +
                ", objectType=" + objectType +
                ", properties=" + properties +
                '}';
    }
}
